﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Markup;
using System.ComponentModel.Composition;
using ShredTheLog.Api;
using System.Diagnostics.Contracts;

namespace ShredTheLog.Controls
{
    [MarkupExtensionReturnType(typeof(string))]
    public sealed class LocalizedStringExtension : MarkupExtension
    {
        public string Key { get; set; }

        public LocalizedStringExtension()
        {
        }

        public LocalizedStringExtension(string key)
        {
            Contract.Requires(!String.IsNullOrWhiteSpace(key));

            Key = key;
        }

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            Contract.Assume(!String.IsNullOrWhiteSpace(Key));
            return Globals.ShredServices.GetLocalizedString(Key);
        }
    }
}
